package com.acme.bankapp.domain.bank;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;

import com.acme.bankapp.domain.bank.accounts.Account;

@SuppressWarnings("serial")
public class Client implements Serializable, IClient {
	private Collection<Account> accounts;
	private String name;
	private Gender gender;

	public Client(String name, Gender gender) {
		super();
		this.name = name;
		this.gender = gender;
		this.accounts = new ArrayList<>();
	}
	
	@Override
	public String toString() {
		return "Client [accounts=" + accounts + ", name=" + name + ", gender="
				+ gender + "]";
	}

	/* (non-Javadoc)
	 * @see com.acme.bankapp.domain.bank.IClient#getName()
	 */
	@Override
	public String getName() {
		return name;
	}
	/* (non-Javadoc)
	 * @see com.acme.bankapp.domain.bank.IClient#getGender()
	 */
	@Override
	public Gender getGender() {
		return gender;
	}
	/* (non-Javadoc)
	 * @see com.acme.bankapp.domain.bank.IClient#getAccounts()
	 */
	@Override
	public Collection<Account> getAccounts() {
		return accounts;
	}

	/* (non-Javadoc)
	 * @see com.acme.bankapp.domain.bank.IClient#addAccount(com.acme.bankapp.domain.bank.accounts.Account)
	 */
	@Override
	public void addAccount(Account account) {
		accounts.add(account);
	}
	
	/* (non-Javadoc)
	 * @see com.acme.bankapp.domain.bank.IClient#getClientSalutation()
	 */
	@Override
	public String getClientSalutation() {
		return gender.getSalutation() + " " + name;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Client other = (Client) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
	
}
